package com.example.demo.drools.base;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 规则输入事实
 */
@SuppressWarnings("serial")
public class RuleFact implements Serializable {

	/**
	 * 通用输入事实集
	 */
	private final Map<String, Object> facts = new HashMap<>();

	/**
	 * 通用输出结果集
	 */
	private final Map<String, Object> results = new HashMap<>();

	/**
	 * 根据属性获取值
	 * @param attr
	 */
	public Object factGet(String attr) {
		return facts.get(attr);
	}

	/**
	 * 移除事实
	 */
	public void factRemove(String attr) {
		facts.remove(attr);
	}

	/**
	 * 设置事实
	 */
	public final void factSet(String attr, Object value) {
		facts.put(attr, value);
	}

	/**
	 * 设置事实集
	 */
	public final void factsSet(Map<String, Object> facts) {
		this.facts.putAll(facts);
	}

	/**
	 * 清除所有事实
	 */
	public final void factClear() {
		facts.clear();
	}

	/**
	 * 设置结果
	 * @param attr
	 * @param value
	 */
	public final void resultSet(String attr, Object value) {
		results.put(attr, value);
	}

	/**
	 * 获取结果
	 * @param attr
	 * @return
	 */
	public final Object resultGet(String attr) {
		return results.get(attr);
	}
	
	/**
	 * 获取结果集
	 * @return
	 */
	public final Map<String, Object> resultsGet() {
		return results;
	}

	@Override
	public String toString() {
		return "RuleFact [facts=" + facts + ", results=" + results + "]";
	}
	
	
	

}
